/*
 * main.cpp
 *
 *  Created on: Jul 29, 2011
 *      Author: dblyth
 */
//	line->SetMainColor(TColor::GetColor((int)(255*(1-2*fabs(mag))),(int)(255*(1-2*fabs(mag-0.5))),(int)(255*(1-2*fabs(mag-1)))));

#include <TApplication.h>
#include <TCanvas.h>
#include <TColor.h>
#include <TEveManager.h>
#include <TEveBox.h>
#include <TFile.h>
#include <TH2D.h>
#include <TStyle.h>
#include <TTree.h>
#include <TView.h>
#include <cmath>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void TCanvas::Closed() {
	Emit("Closed()");

	gApplication->Terminate(0);
}

TEveBox* drawBox(double* pos, double* field, double min, double max);

int main(int argc, char** argv) {
	int argcFake = 0;
	TApplication* app = new TApplication("app", &argcFake, argv);
	Double_t r[5] = { 1, 1, 0, 0, 0 };
	Double_t g[5] = { 0, 1, 1, 1, 0 };
	Double_t b[5] = { 0, 0, 0, 1, 1 };
	Double_t stop[5] = { 0, .25, .5, .75, 1 };
	TColor::CreateGradientColorTable(5, stop, r, g, b, 20);
	TFile* file = new TFile(argv[1]);
	stringstream ss;
	ss << "run" << atoi(argv[2]);
	TTree* tree = (TTree*) file->Get(ss.str().c_str());
	if (!tree) {
		file->Close();
		app->Delete();
		cout << ss << " does not exist" << endl;
		return 0;
	}
	double field[3], pos[3];
	TBranch* fieldb = tree->GetBranch("field");
	TBranch* posb = tree->GetBranch("position");
	fieldb->SetAddress(&field[0]);
	posb->SetAddress(&pos[0]);

	;

	file->Close();
	app->Delete();
	return 0;
}
